package common

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"server/src/global"
	"server/src/model/request"
	"server/src/model/response"
	"server/src/server"
)

type AdminUser struct {
	errMsg string
}

// 获取用户信息
func (a *AdminUser) GetAllUserInfoPage(c *gin.Context) {
	reqInfo := &request.GetUserInfo{}
	if err := c.ShouldBindJSON(reqInfo); err != nil {
		global.GVL_LOG.Error("接受参数失败", err)
		response.FailWithMessage("查看失败，请重新输入正确的参数", c)
		return
	}
	fmt.Println("GetAllUserInfoPage reqInfo is:", reqInfo)
	// 辨别是机器管理员还是超越管理员
	token := c.Request.Header.Get("token")
	userInfo, _ := server.ServerRobotUser.GetUserToRedis(token)
	//去数据库中查找数据
	resInfo, err := server.ServerGroupUser.GetAllUserInfoPage(reqInfo, userInfo.Id)
	if err != nil {
		global.GVL_LOG.Error("接受参数失败", err)
		response.FailWithMessage("查看失败，请重新输入正确的参数", c)
		return
	}
	response.OkWithData(resInfo, c)
}

// 获取用户积分信息记录
func (a *AdminUser) GetAllUserIntegralInfoPage(c *gin.Context) {
	reqInfo := &request.GetUserIntegralInfoPage{}
	if err := c.ShouldBindJSON(reqInfo); err != nil {
		global.GVL_LOG.Error("接受参数失败", err)
		response.FailWithMessage("查看失败，请重新输入正确的参数", c)
		return
	}
	fmt.Println("GetAllUserInfoPage reqInfo is:", reqInfo)
	token := c.Request.Header.Get("token")
	userInfo, _ := server.ServerRobotUser.GetUserToRedis(token)
	//去数据库中查找数据
	resInfo, err := server.ServerGroupUser.GetAllUserIntegralInfoPage(reqInfo, userInfo.Id)
	if err != nil {
		global.GVL_LOG.Error("接受参数失败", err)
		response.FailWithMessage("查看失败，请重新输入正确的参数", c)
		return
	}
	response.OkWithData(resInfo, c)
}
